package com.hiltony.web.controller;

import com.hiltony.web.model.Member;
import com.hiltony.web.model.dto.*;
import com.hiltony.web.service.StatisticsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by hzyangxin1 on 2016/9/16.
 *
 */
@Controller
@RequestMapping("/stat")
public class StatisticsController {

    @Resource
    private StatisticsService statisticsService;

    @RequestMapping("/total")
    public String bootstrap(HttpServletRequest request, Model model){
        return "stat/stat";
    }

    @RequestMapping("/basic")
    @ResponseBody
    public Map get(HttpServletRequest request, Model model){

        Map<String,Object> result =  new HashMap<String,Object>();
        List<GenderStatDto> genderStat = statisticsService.statGender();
        result.put("genderStat",genderStat);
        List<AgeStatDto> ageStat = statisticsService.statAge();
        result.put("ageStat",ageStat);
        result.put("diseaseStat",diseaseStat(new StatCondition()).get("diseaseStat"));
        return result;
    }

    @RequestMapping("/diseasestat")
    @ResponseBody
    public Map diseaseStat(StatCondition statCondition){

        DiseaseDayCntStatDto diseaseDayCntStatDto = statisticsService.getDiseaseStatCnt(statCondition);

        Map<String,Object> result =  new HashMap<String,Object>();

        result.put("diseaseStat",diseaseDayCntStatDto);
        return result;
    }

    @RequestMapping("/warningstat")
    @ResponseBody
    public Map warningStat(StatCondition statCondition){

        List<WarningStatDto> warningStatDtoList= statisticsService.getWarningStat(statCondition);

        Map<String,Object> result =  new HashMap<String,Object>();

        result.put("warningStat",warningStatDtoList);
        return result;
    }

}
